# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=podman
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.2.1
pkgrel=1
pkgdesc='Tool for running OCI-based containers in pods (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://github.com/containers/podman"
license=('spdx:Apache-2.0')
options=('!strip')
makedepends=(
    "${MINGW_PACKAGE_PREFIX}-go"
    "${MINGW_PACKAGE_PREFIX}-cc"
    "git"
)
source=("https://github.com/containers/podman/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('b10004e91a9f5528da450466ec8e6f623eaa28ada79e3044c238895b2c8d1df3')

build() {
    cd "$_realname-$pkgver"

    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-trimpath -modcacherw -ldflags=-linkmode=external"
    case "${CARCH}" in
      i686|x86_64)
        GOFLAGS+=" -buildmode=pie"
        ;;
    esac

    make podman-remote
    make docker-docs
    make win-sshproxy
}

package() {
    cd "$_realname-$pkgver"

    make install.remote install.docker-full install.man install.completions DESTDIR="$pkgdir" PREFIX=${MINGW_PREFIX}
    rm -Rf "${pkgdir}${MINGW_PREFIX}/lib"
    sed -i "s|/usr/bin/||g" "${pkgdir}${MINGW_PREFIX}/bin/docker"

    cp bin/windows/win-sshproxy.exe "${pkgdir}${MINGW_PREFIX}/bin"
}
